package com.webvihar.access2db.utils;
/**
 * PreferenceManager.java
 * 
 * @author Viswanath Kumar Sandu
 */
import android.content.Context;
import android.content.SharedPreferences;


public class PreferencesManager {
	private static final String NAME = "PreferencesManager";

	public static boolean setString(Context context, String key,String value) {
		SharedPreferences.Editor editor = getPreferencesEditor(context);
		editor.putString(key, value);
		return editor.commit();
	}

	public static String getString(Context context, String key) {
		SharedPreferences prefs = getSharedPreferences(context);
		return prefs.getString(key, "");
	}

	public static boolean setBoolean(Context context, String key, boolean value) {
		SharedPreferences.Editor editor = getPreferencesEditor(context);
		editor.putBoolean(key, value);
		return editor.commit();
	}

	public static boolean getBoolean(Context context, String key) {
		SharedPreferences prefs = getSharedPreferences(context);
		return prefs.getBoolean(key, false);
	}

	public static boolean removeKey(Context context, String key) {
		SharedPreferences.Editor editor = getPreferencesEditor(context);
		editor.remove(key);
		return editor.commit();
	}

	private static SharedPreferences.Editor getPreferencesEditor(Context context) {
		SharedPreferences prefs = getSharedPreferences(context);
		SharedPreferences.Editor editor = prefs.edit();
		return editor;
	}

	private static SharedPreferences getSharedPreferences(Context context) {
		SharedPreferences prefs = context.getSharedPreferences(NAME,
				Context.MODE_PRIVATE);
		return prefs;
	}
}
